package com.hellobike.haxing.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hellobike.haxing.common.util.DateUtils;
import com.hellobike.haxing.modules.order.constant.OrderConstants;
import com.hellobike.haxing.modules.order.entity.OrderTimeConfig;
import com.hellobike.haxing.modules.order.mapper.OrderTimeConfigMapper;
import com.hellobike.haxing.modules.order.service.IOrderTimeConfigService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalTime;
import java.util.Date;

/**
 * @Description: 订单相关时间配置
 * @Author: haxing-boot
 * @Date: 2020-02-08
 * @Version: V1.0
 */
@Service
public class OrderTimeConfigServiceImpl extends ServiceImpl<OrderTimeConfigMapper, OrderTimeConfig> implements IOrderTimeConfigService {
    @Override
    public long getPayCloseTimeConfig() {

        QueryWrapper<OrderTimeConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OrderTimeConfig::getType, 3);
        Date localTime = super.getOne(queryWrapper).getTime();
        int hour = localTime.getHours();
        int minute = localTime.getMinutes();
        int second = localTime.getSeconds();
        int seconds = hour * 60 * 60*1000 + minute * 60*1000 + second*1000;
        return Long.valueOf(seconds);
    }

    @Override
    public Date getOrderEndTimeConfig() {
        QueryWrapper<OrderTimeConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OrderTimeConfig::getType, OrderConstants.ORDER_END_TYPE_0);
        return super.getOne(queryWrapper).getTime();
    }
}
